Skip to content

Ping/Pong implementation - #63

Merged
altonen merged 4 commits into
masterfrom
ping-pong
Jan 17, 2022
Merged

Ping/Pong implementation#63
altonen merged 4 commits into
masterfrom
ping-pong

Conversation

@altonen

@altonen altonen commented Jan 13, 2022

Copy link
Copy Markdown
Contributor

This PR implements the Ping/Pong functionality and it's implemented as a state machine on top of the async protocol, i.e., the remote peer can send messages that don't relate to the Ping/Pong functionality in any way but as long as they sent the Pong in time, the connectivity check is concluded as successful. If the remote doesn't respond in time or it responds each time with an invalid nonce, the connection is closed as unresponsive.

This is once again quite a big PR but there's no meaningful way to split it into parts and if it's any solace, there's almost 800 lines of tests and a lot of comments.

Fix couple of old fields and add nonce field to Ping/Pong so that
the protocol is slightly more robust when accepting a Pong from
remote peer.
Ping/Pong is used to test the aliveness of the remote peer and it
works by periodically sending a Ping message and expecting a response
to it within some predefined time period.

This commit implements this functionality as a state machine on
top of the asynchronous protocol by introducing substates to
the default listening state of the `PeerState` enum.

This allows the Ping/Pong functionality to follow a certain path
and catch errors where appropriate while still allowing the remote
peer to essentially send anything they want, as long as they reply
to the Ping message in time and with correct nonce.
Comment thread p2p/src/error.rs Outdated
Comment thread p2p/src/peer.rs
Comment thread p2p/src/peer.rs
Comment thread p2p/src/peer.rs Outdated
Comment thread p2p/src/peer.rs
Comment thread p2p/src/peer.rs Outdated
Comment thread p2p/src/proto/connectivity.rs
Comment thread p2p/src/peer.rs
Comment thread p2p/src/proto/connectivity.rs
Comment thread p2p/src/peer.rs Outdated
Comment thread p2p/src/peer.rs Outdated
Comment thread p2p/src/proto/connectivity.rs Outdated

@TheQuantumPhysicist TheQuantumPhysicist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the few comments I made, it looks fine.

Instead of matching both state and message type at the same time,
match the state first, then call an appropriate function for that
state and match the message type in that function to handle the
(state, message type) combination.

Additionally, add some comments, reword an error message and rename
a few tests functions to be more descriptive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants